package com.controller.ljl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.entity.Customer;
import com.entity.Order;
import com.entity.User;
import com.service.ljl.orderservice;

@Controller
public class ordercontroller {
	@Autowired
	private orderservice orderservice;

	@PostMapping("/order_list")
	@ResponseBody
	public Map<Object, Object> allorder(@RequestParam("pagesize") int pagesize, @RequestParam("curpage") int currage) {
		return orderservice.findallorderright(pagesize, currage);
	}

	@PostMapping("/order_delete")
	@ResponseBody
	public void delete(@RequestParam("id") Long id) {
		System.out.println(id);
		orderservice.delete(id);
	}

	@PostMapping("/all_cus")
	@ResponseBody
	public List<Customer> allcustomer() {
		return orderservice.findcustomer();
	}

	@PostMapping("/all_owner")
	@ResponseBody
	public List<User> alluser() {
		return orderservice.findowner();
	}

	@SuppressWarnings("rawtypes")
	@PostMapping("/order_add")
	@ResponseBody
	public void add(@RequestBody Map map) {
		orderservice.add(map);
	}

	@PostMapping("/order_deleteids")
	@ResponseBody
	public void deleteids(@RequestBody JSONArray orids) {

		orderservice.deleteorders(JSONObject.parseArray(orids.toString(), Long.class));
	}

	@PostMapping("/order_findone")
	@ResponseBody
	public Order findone(@RequestParam(value = "id") Long id) {
		return orderservice.findoneorder(id);
	}

}
